package com.test.textGame.exception;

import org.slf4j.helpers.MessageFormatter;

public class GameRuntimeException extends RuntimeException {
    private String errorCode;
    private String errorMsg;

    private GameRuntimeException(String errorCode, String errorMsg) {
        super(String.format("DemeterRuntimeException{errorCode:%s, errorMsg:%s}", errorCode, errorMsg));
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    private GameRuntimeException(String errorCode, String errorMsg, Throwable cause) {
        super(cause);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public String getErrorCode() {
        return this.errorCode;
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }


    public GameRuntimeException(GameErrorCode errorCode, Throwable cause) {
        this(errorCode.getErrorCode(), errorCode.getErrorMsg(), cause);
    }


    public GameRuntimeException(GameErrorCode errorCode, String... extend) {
        this(errorCode.getErrorCode(), errorCode.getErrorMsg(), extend);
    }

    public GameRuntimeException(GameErrorCode errorCode) {
        this(errorCode.getErrorCode(), errorCode.getErrorMsg());
    }

    public GameRuntimeException(String errorCode, String errorMsg, String... extend) {
        this(errorCode, MessageFormatter.arrayFormat(errorMsg, extend).getMessage());
    }
    public GameRuntimeException(GameErrorCode errorCode, Throwable cause, String... extend) {
        this(errorCode.getErrorCode(), MessageFormatter.arrayFormat(errorCode.getErrorMsg(), extend).getMessage(), cause);
    }
}
